/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	Texture2D.h
*
*	Description -	Class representing a 2D texture.
*
*	Comments	-	
*
*	Modification History:
*			Name			   Date					Description
*			MrCodeSushi	-	10/11/2011	-	Creation of this file
**************************************************************************************/
#ifndef _PSX_TEXTURE_2D_H_
#define _PSX_TEXTURE_2D_H_

#include "PulseSTD.h"
#include "GraphicsInfrastructure.h"
#include "ShaderResource.h"
#include "GraphicsTypes.h"
#include "ResourcePoolItem.h"
#include "StoragePool.h"
#include "String.h"

// Resource Views
#include "DepthStencilViewDesc.h"
#include "ShaderResourceViewDesc.h"

namespace Pulse
{
	struct Texture2DDesc : public BaseResDesc
	{
	public:

		Texture2DDesc( void );

		~Texture2DDesc( void );
		
		void Set( ETextureUsage::Type _usage, EGraphicsFormat::Type _format, UINT _width, UINT _height, UINT _arraySize = 1 );
		
		void SetToLoad( const CHAR *pFilename );

		void SetAsCubeMap( const SIZE_T size, const BOOL bDynamic );

		void SetAsDepthBuffer( UINT _width, UINT _height, EGraphicsFormat::Type _format = EGraphicsFormat::D24_UNORM_S8_UINT, BOOL bBindAsResource = FALSE );

		void SetAsRenderTarget( UINT _width, UINT _height );
		
		void SetAsSwapChainBuffer( void *pSwapChainBuffer );

		virtual const ResourceCode GetType( void ) const { return ResourceCode( EResource::VIDEO, EVideoResource::TEXTURE2D ); }

		void Clear( void );

		void SetDepthStencilView( const DepthStencilViewDesc *pView );

		void SetShaderResourceView( const ShaderResourceViewDesc *pView );

		Texture2DDesc & operator = ( const Texture2DDesc &rhs );

		String					filename;
		EGraphicsFormat::Type	format;
		ETextureUsage::Type		usage;
		UINT					width;
		UINT					height;
		UINT					arraySize;
		BOOL					bGenerateMips;
		BOOL					bTextureCube; // Should we be making a different texture for this?
		void					*pData;

		// Resource Views
		DepthStencilViewDesc	*m_pDSVConfig;
		ShaderResourceViewDesc	*m_pSRVConfig;
	};

	class Texture2D : public IResourcePoolItem, public ShaderResource
	{
	public:

		virtual ~Texture2D( void );

		// These defines the base interface for all derived resources
		virtual BOOL CreateResource( BaseResDesc *pDesc );
		virtual BOOL DestroyResource( void );
		virtual BOOL LoadResource( void );				
		virtual BOOL UnloadResource( void );

		virtual const ResourceCode GetType( void ) const { return ResourceCode( EResource::VIDEO, EVideoResource::TEXTURE2D ); }

	private:

		PSX_MakeStoragePoolFriend( Texture2D );

		Texture2D( void );

		EErrorCode::Type Initialize( void );

		void Cleanup( void );

		UINT GetDescMipLevels( void );

		D3D11_USAGE GetDescUsage( void );

		UINT GetDescBindFlags( void );

		UINT GetDescCPUUsageFlags( void );

		UINT GetDescMiscFlags( void );

	private:

		Texture2DDesc	m_desc;
		ID3D11Texture2D *m_pTexture;

	};
}

#endif /* _PSX_TEXTURE_2D_H_ */